﻿using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PhysicalExamination5.Interface;
using PhysicalExamination5.Service.DataMaintenance;
using PhysicalExamination5.WebApi.Utility.JWT;

namespace PhysicalExamination5.WebApi.Controllers
{
    /// <summary>
    /// 公共处理
    /// </summary>
    [ApiController]
    [ApiVersion("1.0")]
    [Route("[controller]/v{version:apiVersion}")]
    public class PublicController : Controller
    {
        private readonly IPublic _IPublic;
        private readonly ICustomJWTService _ICustomJWTService;
        private readonly IHttpContextAccessor _httpContextAccessor;
        private static readonly ILog log = LogManager.GetLogger(typeof(IndexController));

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="IPublic"></param>
        /// <param name="ICustomJWTService"></param>
        /// <param name="httpContextAccessor"></param>
        public PublicController(IPublic IPublic, ICustomJWTService ICustomJWTService, IHttpContextAccessor httpContextAccessor)
        {
            _IPublic = IPublic;
            _ICustomJWTService = ICustomJWTService;
            _httpContextAccessor = httpContextAccessor;

            //配置日志ip地址参数信息
            string ipAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            GlobalContext.Properties["localIpAddress"] = ipAddress;
        }
        /// <summary>
        /// 维护界面查询所属院区
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        [Route("[action]")]
        public IActionResult GetAllYuanQuSel()
        {
            log.Debug($@"API:{System.Reflection.MethodBase.GetCurrentMethod().Name}");
            return Ok(_IPublic.GetAllYuanQuSel());
        }
    }
}
